<?php


namespace app\partneradmin\controller;


use app\common\controller\partneradmin\Base;
use app\partneradmin\model\FromConfig;

class Fromcnfig extends Base
{
    protected $noNeedLogin = [];

    protected $model;


    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\partneradmin\model\FromConfig();
    }

    /**
     * 查看
     */
    public function index()
    {
        //设置过滤方法
        if ($this->request->isPost()) {
            $categoryId = $this->request->post('category_id', '');
            $sort = $this->request->post('sort', 'weight');
            $order = $this->request->post('order', 'desc');
            $adminId = $this->request->post('admin_id', '');
            $countryConfigId = $this->request->post('country_config_id', '');
            if (empty($categoryId)) {
                $this->error('category_id缺失！');
            }
            if (empty($countryConfigId)) {
                $this->error('country_config_id缺失！');
            }
            if ($adminId != '') {
                $where['admin_id'] = $adminId;
            }
            $where['category_id'] = $categoryId;
            $where['country_config_id'] = $countryConfigId;
            $where['is_del'] = 0;
            $list = $this->model
                ->field('*')
                ->where($where)
                ->order($sort, $order)
                ->select();
            $data = [
                'list' => $list
            ];
            $this->success('列表', '', $data);
        }
    }

    /**
     * 获取表单配置
     */
    public function getFormConfigInfo($country_config_id = 1)
    {
        $where = [
            'is_del' => 0,
            'status' => 1
        ];
        $catList = \app\admin\model\Category::field('id,nickname')->where($where)->where('pid', '=', 33)->select()->toArray();
        $where['country_config_id'] = $country_config_id;
        $fromList = \app\admin\model\FromConfig::field('name,title,type,value,category_id')->where($where)->order('weight', 'desc')->select()->toArray();
        $list = [];
        foreach ($catList as $val) {
            $info = [];//初始化数组
            $info = $val;
            $info['from_list'] = [];
            foreach ($fromList as $v) {
                if ($v['category_id'] == $val['id']) {
                    unset($v['category_id']);
                    $info['from_list'][] = $v;
                }
            }
            $list[] = $info;
        }
        return $list;
    }

    /**
     * 禁止新增
     */
    public function add()
    {
        $this->error('添加失败！该模块不允许添加');
    }
    /**
     * 禁止编辑
     */
    public function edit($ids = null)
    {
        $this->error('修改失败！该模块合作方不允许编辑');
    }
    /**
     * 禁止删除
     */
    public function del($ids = null)
    {
        $this->error('该模块合作方不允许操作');
    }
}